package GoodsPackage;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/querygood.do")
public class QueryGoodServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        try {
            String goods_id = request.getParameter("goods_id");

           GoodsDao goodsDao = new GoodsDao();
            Good good = goodsDao.queryGoodByGoodid(goods_id);
            if (good != null) {
                // Display user information in the response
                System.out.println("dsaasdad");
                response.getWriter().print("商品信息:<br>");
                response.getWriter().print("商品编号: " + good.getGoods_id() + "<br>");
                response.getWriter().print("商品名称: " + good.getGoods_name() + "<br>");
                response.getWriter().print("商品类型: " + good.getGoods_category() + "<br>");
                response.getWriter().print("商品价格: " + good.getUnitprice() + "<br>");
                response.getWriter().print("商品库存: " + good.getStock() + "<br>");
                response.getWriter().print("商品工厂: " + good.getFactory() + "<br>");
                response.getWriter().print("商品图片地址: " + good.getPic() + "<br>");
                response.getWriter().print("商品细节: " + good.getDetails() + "<br>");
                // Include other user information as needed
            } else {
                response.getWriter().print("没有找到商品！");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // Handle POST requests if needed
    }
}
